package com.gtq.uhome.controller;

import com.gtq.uhome.pojo.Staff;
import com.gtq.uhome.result.Result;
import com.gtq.uhome.service.OperatorService;
import com.gtq.uhome.vo.Operator;
import com.gtq.uhome.vo.OperatorLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping(value = "/operator")
@CrossOrigin
@Api(tags = "系统管理——操作员——何凡")
public class OperatorController {

    @Resource
    private OperatorService operatorService;//实例化

    /**
     * 查询全部操作员信息
     * @return
     */
    @GetMapping(value = "/operatorAll")
    @ResponseBody
    @ApiOperation("查询全部操作员信息")
    public Result<List<Operator>>selectByOperatorAll(){
        return Result.ok(operatorService.selectAll());
    }

    /**
     * 根据条件模糊查询所有操作员信息
     * @param operator
     * @return
     */
    @PostMapping(value = "/operator")
    @ResponseBody
    @ApiOperation("根据条件模糊查询所有操作员信息")
    public Result<List<Operator>>selectByOperator(@RequestBody Operator operator){
        return Result.ok(operatorService.selectAllLike(operator));
    }

    /**
     * 添加操作员
     * @param operator
     * @return
     */
    @PostMapping(value ="/insertStaffRole")
    @ResponseBody
    @ApiOperation("添加操作员")
    public Result insertStaffRole(@RequestBody Operator operator) {
        return operatorService.insertStaffRole(operator)==1?Result.ok("添加成功"):Result.failed("添加失败");
    }

    /**
     * 修改操作员相关信息
     * @param operator
     * @return
     */
    @PutMapping(value ="/updateStaffRole")
    @ResponseBody
    @ApiOperation("修改操作员相关信息")
    public Result updateStaffRole(@RequestBody Operator operator) {
        return operatorService.updateAll(operator)==1?Result.ok("修改成功"):Result.failed("修改失败");
    }

    /**
     * 删除操作员
     * @param
     * @return
     */
    @PutMapping(value ="/deleteStaffRole")
    @ResponseBody
    @ApiOperation("删除操作员")
    public Result deleteStaffRole(@RequestBody List<Operator> operators) {
        return operatorService.deleteAll(operators)==1?Result.ok("删除成功"):Result.failed("删除失败");
    }

    /**
     * 重置操作员密码
     * @param staff
     * @return
     */
    @PutMapping(value ="/updatePassword")
    @ResponseBody
    @ApiOperation("重置操作员密码")
    public Result updatePassword(@RequestBody Staff staff) {
        return operatorService.updatePassword(staff)==1?Result.ok("重置密码成功"):Result.failed("重置密码失败");
    }
}
